package com.xiaofeng.pochi.controller;

import com.xiaofeng.pochi.common.Page;
import com.xiaofeng.pochi.common.Result;
import com.xiaofeng.pochi.pojo.ShopUser;
import com.xiaofeng.pochi.pojo.vo.ShopUserStatisticVo;
import com.xiaofeng.pochi.pojo.vo.ShopUserVo;
import com.xiaofeng.pochi.service.ShopUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 *
 * @Author: chc
 * @Date: 2022/09/24/23:35
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class ShopUserController {

    @Autowired
    private ShopUserService shopUserService;

    /**
     * 分页查询
     *
     * @param page
     * @return
     */
    @RequestMapping(value = "/getByPage", method = RequestMethod.POST)
    public Result<Page<ShopUser>> getByPage(@RequestBody Page<ShopUser> page) {
        page = shopUserService.getByPage(page);
        return new Result<>(page);
    }


    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result<ShopUserVo> get(@PathVariable Long id) {
        ShopUserVo shopUserVo = shopUserService.get(id);
        return new Result<>(shopUserVo);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    public Result<?> delete(@PathVariable Long id) {
        shopUserService.delete(id);
        return new Result<>("删除成功");
    }


    /**
     * 解封
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/enableById/{id}", method = RequestMethod.PUT)
    public Result<?> enableById(@PathVariable Long id) {
        shopUserService.enableById(id);
        return new Result<>("操作成功");
    }

    /**
     * 封禁
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/disableById/{id}", method = RequestMethod.PUT)
    public Result<?> disableById(@PathVariable Long id) {
        shopUserService.disableById(id);
        return new Result<>("操作成功");
    }

    /**
     * 查询累计消费最多的前十个用户
     *
     * @return
     */
    @RequestMapping(value = "/getTopStatistic", method = RequestMethod.GET)
    public Result<List<ShopUserStatisticVo>> getTopStatistic() {
        List<ShopUserStatisticVo> list = shopUserService.getTopStatistic();
        return new Result<>(list);
    }

}
